import request from '@/utils/request'

export interface SystemLogQuery {
  page: number
  size: number
  username?: string
  action?: string
  level?: string
  startTime?: string
  endTime?: string
}

export interface SystemLog {
  id: number
  userId?: number
  username?: string
  action: string
  resource?: string
  description?: string
  ipAddress?: string
  userAgent?: string
  level: string
  createdAt: string
}

export const systemLogApi = {
  // 获取系统日志列表
  getLogs(params: SystemLogQuery) {
    return request.get('/system/logs', { params })
  },

  // 清理过期日志
  cleanLogs(days: number = 30) {
    return request.delete(`/system/logs/clean?days=${days}`)
  },

  // 导出日志
  exportLogs(params: SystemLogQuery) {
    return request.get('/system/logs/export', { 
      params,
      responseType: 'blob'
    })
  }
}